class EntityData:
	var hp:int
	var mp:int
	var maxHp:int
	var maxMp:int
	
	var lifeLv:int
	var focusLv:int
	var strengthLv:int
	var intelligenceLv:int	
	var dexterityLv:int
	var luckyLv:int
	
	var spriteFrames
	var uiHeadIcon
	
	var careerConfig
	
	var equipmentsData = []
	var equipmentsDataDict = {}
	var weaponsData = []
	
	var equipmentAffectProps = [Consts.PROP_ANTI_SLASH, Consts.PROP_ANTI_MACE, Consts.PROP_ANTI_PIERCE,Consts.PROP_ANTI_FIRE, Consts.PROP_ANTI_THUNDER, Consts.PROP_ANTI_POISON, Consts.PROP_ANTI_BLEED, Consts.PROP_ANTI_SLEEP, Consts.PROP_ANTI_MADNESS, Consts.PROP_ANTI_DEAD, Consts.PROP_ANTI_FROST, Consts.PROP_CRITICAL, Consts.PROP_CRITICAL_DAMAGE, Consts.PROP_AVOID, Consts.PROP_MOVE]
	var attributeAffectProps = [Consts.PROP_ANTI_SLASH, Consts.PROP_ANTI_MACE, Consts.PROP_ANTI_PIERCE,Consts.PROP_ANTI_FIRE, Consts.PROP_ANTI_THUNDER, Consts.PROP_ANTI_POISON, Consts.PROP_ANTI_BLEED, Consts.PROP_ANTI_SLEEP, Consts.PROP_ANTI_MADNESS, Consts.PROP_ANTI_DEAD, Consts.PROP_ANTI_FROST, Consts.PROP_CRITICAL, Consts.PROP_CRITICAL_DAMAGE, Consts.PROP_AVOID, Consts.PROP_MOVE] 
	var antiProps = [Consts.PROP_ANTI_SLASH, Consts.PROP_ANTI_MACE, Consts.PROP_ANTI_PIERCE, Consts.PROP_ANTI_FIRE, Consts.PROP_ANTI_THUNDER, Consts.PROP_ANTI_POISON, Consts.PROP_ANTI_BLEED, Consts.PROP_ANTI_SLEEP, Consts.PROP_ANTI_MADNESS, Consts.PROP_ANTI_DEAD, Consts.PROP_ANTI_FROST]
	
	#battle
	var battlePos = Vector2.INF
	var battleFace = ""
	var battleActionFinish = false
	var battleIsEnemy = false
	
	
	func newBorn(_careerConfig):
		careerConfig = _careerConfig
		
		lifeLv = int(careerConfig.baseLifeLv)
		focusLv = int(careerConfig.baseFocusLv) 
		strengthLv = int(careerConfig.baseStrengthLv)
		intelligenceLv = int(careerConfig.baseIntelligenceLv)
		dexterityLv = int(careerConfig.baseDexterityLv)
		luckyLv = int(careerConfig.baseLuckyLv)
		
		hp = int(lifeLv) * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_LIFE].hp)
		mp = int(focusLv) * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_FOCUS].mp)
		
		maxHp = hp
		maxMp = mp
		
	
	func attributeAttackBonusPoint(weapon):
		var weaponConfig = weapon.config
		var attributeBonusPoint = 0
			
		if weaponConfig.strengthBonus != "/":
			var temp = ConfigClasses.AttributeWeaponAttackBonusConfig.configsDict[weaponConfig.strengthBonus].bonusValue
			var bonusBasePoint = float(temp)
			var bonusAttributePoint = strengthLv - int(weaponConfig.requireStrength)
			if bonusAttributePoint < 0: bonusAttributePoint = 0
			attributeBonusPoint += bonusAttributePoint * bonusBasePoint
		
		if weaponConfig.intelligenceBonus != "/":
			var bonusBasePoint =  float(ConfigClasses.AttributeWeaponAttackBonusConfig.configsDict[weaponConfig.intelligenceBonus].bonusValue)
			var bonusAttributePoint = intelligenceLv - int(weaponConfig.requireIntelligence)
			if bonusAttributePoint < 0: bonusAttributePoint = 0
			attributeBonusPoint += bonusAttributePoint * bonusBasePoint
			
		if weaponConfig.dexterityBonus != "/":
			var bonusBasePoint =  float(ConfigClasses.AttributeWeaponAttackBonusConfig.configsDict[weaponConfig.dexterityBonus].bonusValue)
			var bonusAttributePoint = dexterityLv - int(weaponConfig.requireDexterity)
			if bonusAttributePoint < 0: bonusAttributePoint = 0
			attributeBonusPoint += bonusAttributePoint * bonusBasePoint
			
		if weaponConfig.luckyBonus != "/":
			var bonusBasePoint =  float(ConfigClasses.AttributeWeaponAttackBonusConfig.configsDict[weaponConfig.luckyBonus].bonusValue)
			var bonusAttributePoint = luckyLv - int(weaponConfig.requireLucky)
			if bonusAttributePoint < 0: bonusAttributePoint = 0
			attributeBonusPoint += bonusAttributePoint * bonusBasePoint
	
		return attributeBonusPoint
		
	
	func weaponLvBonusPercent(weaponData):
		return float(ConfigClasses.WeaponLevelConfig.configsDict[str(weaponData.lv)].percent) 
		
	
	func attack(attackType):
		var result = 0
		
		if weaponsData.size() > 0:
			var weapon = weaponsData[0]
			
			var weaponBaseAttack = 0
			if attackType == Consts.PROP_PHYSICAL_ATTACK:
				weaponBaseAttack = float(weapon.config.physicalAttack)
			elif attackType == Consts.PROP_FIRE_ATTACK:
				weaponBaseAttack = float(weapon.config.fireAttack)
			elif attackType == Consts.PROP_THUNDER_ATTACK:
				weaponBaseAttack = float(weapon.config.thunderAttack)
				
			var lvBonusPercent = weaponLvBonusPercent(weapon)
			var attributeBonusPoint = attributeAttackBonusPoint(weapon)
			
			result = (weaponBaseAttack + attributeBonusPoint) * lvBonusPercent
			
		return result
		
	
	func effectPoint(effectType):
		var result = 0
		
		if weaponsData.size() > 0:
			var weapon = weaponsData[0]
			
			var basePoint = 0
			if effectType == Consts.PROP_POISON:
				basePoint = weapon.config.poison
			elif effectType == Consts.PROP_BLEED:
				basePoint = weapon.config.bleed
			elif effectType == Consts.PROP_SLEEP:
				basePoint = weapon.config.sleep
			elif effectType == Consts.PROP_MADNESS:
				basePoint = weapon.config.madness
			elif effectType == Consts.PROP_DEAD:
				basePoint = weapon.config.dead
			elif effectType == Consts.PROP_FROST:
				basePoint = weapon.config.frost
			
			var lvBonusPercent = weaponLvBonusPercent(weapon)
			
			result = float(basePoint) * lvBonusPercent
			
		return result
		
	
	func otherProps():
		var result = {}
		
		result[Consts.PROP_CRITICAL] = 0
		result[Consts.PROP_CRITICAL_DAMAGE] = 0
		result[Consts.PROP_AVOID] = 0
		result[Consts.PROP_MOVE] = float(careerConfig.baseMoveDistance)
		
		if weaponsData.size() > 0:
			var weapon = weaponsData[0]
			
			result[Consts.PROP_CRITICAL] += weapon.critical()
			result[Consts.PROP_CRITICAL_DAMAGE] += weapon.criticalDamage()
			result[Consts.PROP_AVOID] += weapon.avoid()
			
		var attributeAffectPoint = attributeAffectPoint()
		var equipmentAffectPoint = equipmentAffectPoint()
		
		result[Consts.PROP_CRITICAL] += attributeAffectPoint[Consts.PROP_CRITICAL]
		result[Consts.PROP_CRITICAL_DAMAGE] += attributeAffectPoint[Consts.PROP_CRITICAL_DAMAGE]
		result[Consts.PROP_AVOID] += attributeAffectPoint[Consts.PROP_AVOID]
		result[Consts.PROP_MOVE] += attributeAffectPoint[Consts.PROP_MOVE]
		
		result[Consts.PROP_CRITICAL] += equipmentAffectPoint[Consts.PROP_CRITICAL]
		result[Consts.PROP_CRITICAL_DAMAGE] += equipmentAffectPoint[Consts.PROP_CRITICAL_DAMAGE]
		result[Consts.PROP_AVOID] += equipmentAffectPoint[Consts.PROP_AVOID]
		result[Consts.PROP_MOVE] += equipmentAffectPoint[Consts.PROP_MOVE]
		
		return result
		
	
	func attributeAffectPoint():
		var result = {}
		
		for prop in attributeAffectProps:
			result[prop] = lifeLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_LIFE].get(prop))
			result[prop] += focusLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_FOCUS].get(prop))
			result[prop] += strengthLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_STRENGTH].get(prop))
			result[prop] += intelligenceLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_INTELLIGENCE].get(prop))
			result[prop] += dexterityLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_DEXTERITY].get(prop))
			result[prop] += luckyLv * float(ConfigClasses.AttributeEffectConfig.configsDict[Consts.ATTR_LUCKY].get(prop))
		
		return result
		

	func equipmentAffectPoint():
		var result = {}
		
		for prop in equipmentAffectProps:
			result[prop] = 0
		
		for equipment in equipmentsData:
			for prop in equipmentAffectProps:
				result[prop] += float(equipment.config.get(prop))
		
		return result
		
	
	func antiPoint():
		var result = {}
		
		var attributeAffectPointDict = attributeAffectPoint()
		var equipmentAffectPointDict = equipmentAffectPoint()
		
		for prop in antiProps:
			result[prop] = attributeAffectPointDict[prop] + equipmentAffectPointDict[prop]
		
		return result
		
	
	func attackType():
		var result = "无"
		
		if weaponsData.size() > 0:
			var weapon = weaponsData[0]
			result = ConfigClasses.AttackTypeConfig.configsDict[weapon.config.attackType].name
			
		return result
		
	
	func calcPropertiesByWeapon(weapon):
		var tempWeaponsData = weaponsData
		var tempEquipmentsData = equipmentsData
		var tempEquipmentsDataDict = equipmentsDataDict
		
		weaponsData = [weapon]
		equipmentsData = []
		equipmentsDataDict = {}
		
		var result = getProperties()
		
		weaponsData = tempWeaponsData
		equipmentsData = tempEquipmentsData
		equipmentsDataDict = tempEquipmentsDataDict
		
		return result
		
	
	func getAttributes():
		var result = {}
		
		result[Consts.ATTR_LIFE + "Lv"] = lifeLv
		result[Consts.ATTR_FOCUS + "Lv"] = focusLv
		result[Consts.ATTR_STRENGTH + "Lv"] = strengthLv
		result[Consts.ATTR_INTELLIGENCE + "Lv"] = intelligenceLv
		result[Consts.ATTR_DEXTERITY + "Lv"] = dexterityLv
		result[Consts.ATTR_LUCKY + "Lv"] = luckyLv
		
		return result
		
	
	func getProperties():
		var result = {}
		
		result[Consts.PROP_HP] = hp
		result[Consts.PROP_MAX_HP] = maxHp
		result[Consts.PROP_MP] = mp
		result[Consts.PROP_MAX_MP] = maxMp
		result[Consts.PROP_PHYSICAL_ATTACK] = attack(Consts.PROP_PHYSICAL_ATTACK) 
		result[Consts.PROP_FIRE_ATTACK] = attack(Consts.PROP_FIRE_ATTACK)
		result[Consts.PROP_THUNDER_ATTACK] = attack(Consts.PROP_THUNDER_ATTACK) 
		result[Consts.PROP_POISON] = effectPoint(Consts.PROP_POISON)
		result[Consts.PROP_BLEED] = effectPoint(Consts.PROP_BLEED)
		result[Consts.PROP_SLEEP] = effectPoint(Consts.PROP_SLEEP)
		result[Consts.PROP_MADNESS] = effectPoint(Consts.PROP_MADNESS)
		result[Consts.PROP_DEAD] = effectPoint(Consts.PROP_DEAD)
		result[Consts.PROP_FROST] = effectPoint(Consts.PROP_FROST)
		
		var antiPointDict = antiPoint()
		for prop in antiProps:
			result[prop] = antiPointDict[prop]
			
		var otherProps = otherProps()
		result[Consts.PROP_CRITICAL] = otherProps[Consts.PROP_CRITICAL]
		result[Consts.PROP_CRITICAL_PERCENT] = result[Consts.PROP_CRITICAL] * 100
		result[Consts.PROP_CRITICAL_DAMAGE] = otherProps[Consts.PROP_CRITICAL_DAMAGE]
		result[Consts.PROP_CRITICAL_DAMAGE_PERCENT] = result[Consts.PROP_CRITICAL_DAMAGE] * 100
		result[Consts.PROP_AVOID] = otherProps[Consts.PROP_AVOID]
		result[Consts.PROP_AVOID_PERCENT] = result[Consts.PROP_AVOID] * 100
		result[Consts.PROP_MOVE] = floor(otherProps[Consts.PROP_MOVE]) 
		
		result[Consts.PROP_ATTACK_TYPE] = attackType()
		
		return result
			
		
	func equipWeapon(weaponData):
		weaponsData = [weaponData]
		
	
	func equipEquipment(equipmentData):
		var loc = equipmentData.config.type
		
		var oldEquipment = null
		if equipmentsDataDict.has(loc):
			oldEquipment = equipmentsDataDict[loc]
			
		if oldEquipment:
			equipmentsData.erase(oldEquipment)
			equipmentsDataDict.erase(loc)
			
		equipmentsData.append(equipmentData)
		equipmentsDataDict[loc] = equipmentData
		
		
	func getPropMove():
		var props = getProperties()
		return props[Consts.PROP_MOVE]
